<!--考核列表开始-->
<template>
  <div class="checkListContainer checkListContainer1">
    <van-sticky>
      <!--头部bar开始-->
      <p class="titlebar">
        <span @click="goback">
          <van-icon name="arrow-left" size="18" />
        </span>
        <span>利润指标</span>
        <span>
          <van-icon name="wap-home" size="18" @click="toHome" />
        </span>
      </p>
      <!--头部bar结束-->
    </van-sticky>
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh" success-text="刷新成功">
      <div class="ListContent" v-for="(item, index) in List" :key="index">
        <!-- <div class="content" @click="toDetail(item.id)">
          <p class="contentleft">{{item.project_company_name}}</p>
          <p class="contentright">{{item.checkdate}}</p>
        </div>-->
        <div class="content1" @click="toDetail(item.id,item.statu)">
          <div class="content">
            <p class="contentleft">{{item.project_company_name}}</p>
            <p class="contentright">{{item.update_date}}</p>
          </div>
          <div class="historycont">
            <p class="historycontp">
              <span class="left">考核次数:1次</span>
              <span class="right">分数:{{item.score}}</span>
            </p>
          </div>
        </div>
      </div>

      <div class="noData" v-show="List.length<=0">
        <van-image width="163px" height="120px" fit="contain" :src="nochekData" />
        <p>暂无数据 ！</p>
      </div>
    </van-pull-refresh>
    <!--列表结束-->
    <!--新建按钮-->
    <div class="cleanerCheckBut cleanerCheckBut1" v-if="statu==0&&user_department_type==2 ">
      <router-link to="/profitCheck">
        <button class="newbut">新建</button>
      </router-link>
    </div>
  </div>
</template>
<script>
import { mapState } from "vuex";
export default {
  computed: {
    ...mapState({
      token: state => state.Authorization,
      role_id: state => state.userData.role_id,
      user_department_type: state => state.userData.department_type, //人员类型
      user_department_id: state => state.userData.department_id, // 人员id
      user_group_department_id: state => state.userData.group_department_id,
      user_project_company_id: state => state.userData.project_company_id,
      user_project_id: state => state.userData.project_id
    })
  },

  data() {
    return {
      noauth: require("../../../../static/image/noauth.png"),
      nochekData: require("../../../../static/image/nochekData.png"),
      //上拉加载
      loading: false,
      finished: false,
      //参数赋值
      group_department_id: "",
      project_company_id: "",
      project_id: "",
      district_id1: "",
      template_id: "",
      statu: 0,
      List: [],
      checkdate: "",
      //下拉刷新
      refreshing: false
    };
  },
  mounted() {
    this.getLoadData();
    var that = this;
    document.addEventListener("backbutton", that.backbutton, false);
  },
  destroyed() {
    var that = this;
    document.removeEventListener("backbutton", that.backbutton, false);
  },
  methods: {
    goback() {
      if (this.$route.path == "/profitList") {
        this.$router.push({
          path: "/checkIndex"
        });
      }
    },
    backbutton() {
      if (this.$route.path == "/profitList") {
        this.$router.push({
          path: "/checkIndex"
        });
      }
    },
    onRefresh() {
      this.loading = false;
      this.finished = false;
      this.List = [];
      this.getLoadData();
    },
    //上拉加载

    toHome() {
      this.$router.push({
        //核心语句
        path: "/home" //跳转的路径
      });
    },

    //拿到数据
    getLoadData() {
      this.$toast.loading({
        mask: true,
        message: "加载中...",
        duration: 5000
      });
      this.showDate();
      var params = {
        token: this.token,
        checkdate: this.checkdate
      };
      this.$http
        .get(
          `${this.$basePath}?service=App.ProjectCompany.GetProfitCheckList&api=86`,
          {
            params: params
          }
        )
        .then(res => {
          if (res.ret == 200) {
            this.$toast.clear();
            this.refreshing = false;
            this.List = res.data;
          } else {
            this.$toast({ message: res.msg });
          }
        });
    },
    //项目公司考核详情
    toDetail(id) {
      this.$router.push({
        //核心语句
        path: "/profitCheckUpdate", //跳转的路径
        query: {
          //路由传参时push和query搭配使用 ，作用时传递参数
          id
        }
      });
    },
    showDate() {
      var d = new Date();
      let year = d.getFullYear();
      let month = d.getMonth() + 1;
      let day = d.getDate();
      if (month >= 1 && month <= 9) {
        month = `0${month}`;
      }
      if (day >= 1 && day <= 9) {
        day = `0${day}`;
      }
      this.checkdate = year + "-" + month;
    }
  }
};
</script>
<style lang="less" scoped>
@import "../../../assets/css/check";
.van-pull-refresh {
  height: 100%;
}
</style>